package weaver.interfaces.xfjt.action;

import com.weaver.general.BaseBean;
import com.weaver.general.Util;
import weaver.conn.RecordSet;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

/**
 * @Title: ecology-idea
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2022-12-15
 * @Description: 在线考试流程回写考试统计台账明细和试卷台账
 * @ModifyLog:
 **/
public class WeaZxkslcAction extends BaseBean implements Action {
    @Override
    public String execute(RequestInfo requestInfo) {
        String requestid = requestInfo.getRequestid();
        String tablename = requestInfo.getRequestManager().getBillTableName();
        writeLog(">>>>>WeaZxkslcAction>>>>>requestid=" + requestid);
        RecordSet rs = new RecordSet();
        try {
            rs.executeQuery("select dtr,jmsjid,kslx,dtsc,ksdjsj,djjssj,sjdf,sjsplc,kszt,sfzk from " + tablename + " where requestid=?", requestid);
            rs.next();
            String dtr = Util.null2String(rs.getString("dtr"));
            String dtsc = Util.null2String(rs.getString("dtsc"));
            String ksdjsj = Util.null2String(rs.getString("ksdjsj"));
            String djjssj = Util.null2String(rs.getString("djjssj"));
            double sjdf = Util.getDoubleValue(rs.getString("sjdf"),0);
            String sjsplc = Util.null2String(rs.getString("sjsplc"));
            String kszt = Util.null2String(rs.getString("kszt"));
            String sfzk = Util.null2String(rs.getString("sfzk"));
            String jmsjid  = getIdToRequestid(sjsplc,"uf_kstjtz");
            writeLog(">>>>>WeaZxkslcAction>>>>>jmsjid=" + jmsjid+",sjdf="+sjdf);
            String sql  ="update uf_kstjtz_dt1 set ksdjsj='"+ksdjsj+"',sjtjsj='"+djjssj+"',dtscfz='"+dtsc+"',sjdf='"+sjdf+"'," +
                        "sjxq='"+requestid+"',kszt='"+kszt+"',sfzk='"+sfzk+"' where mainid=? and dtr=?";
                rs.executeUpdate(sql,jmsjid,dtr);
            return Action.SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            requestInfo.getRequestManager().setMessageid("111111");
            requestInfo.getRequestManager().setMessagecontent("Action接口异常！");
            return Action.FAILURE_AND_CONTINUE;
        }
    }
    public static String getIdToRequestid(String requestid,String tablename){
        RecordSet rs = new RecordSet();
        rs.executeQuery("select id from "+tablename+" where lcck=?",requestid);
        rs.next();
        return Util.null2String(rs.getString(1));
    }

}
